package service;

import java.util.List;

import cjgl.dao.GradeDAO;
import cjgl.dao.StudentDAO;
import cjgl.entity.Course;
import cjgl.entity.Grade;

public class GradeService {
   private GradeDAO gradeDAO=new GradeDAO();
   StudentDAO studentDAO = new StudentDAO();
public void delete(Integer id) {
	gradeDAO.delete(id);
}


public Grade findById(Integer id) {
	return gradeDAO.findById(id);
}
public List<Grade> findAll() {
	return gradeDAO.findAll();
}
public void sava(Grade grade) {
	Integer id=grade.getId();
	if(id==null) {
		gradeDAO.insert(grade);
	}else {
		gradeDAO.update(grade);
	}

}
public void delete(Grade grade) {
	gradeDAO.delete(grade.getId());
	

}
public List<Grade>findByStudent(Integer stuId){
	return gradeDAO.findByStudentId(stuId);
}


public Grade findByStudentIdAndCourseId(Integer studentId, Integer courseId) {
	return gradeDAO.findByStudentIdAndCourseId(studentId, courseId);
}


public List<Course> findCourseByBjId(Integer bjId) {
	return gradeDAO.findCourseByBjId(bjId);
}


public List<List<Object>> getCjb(Integer bjId, List<Course> courses) {
	/*List<List<Object>> cjb = new ArrayList<List<Object>>();
	List<Student> students = studentDAO.findByTbClassId(bjId);
	for (Student student : students) {
		List<Object> row = new ArrayList<Object>();
		row.add(student.getStuNo());
		row.add(student.getName());
		for(Course course : courses) {
			Grade grade = findByStudentIdAndCourseId(student.getId(),course.getId());
			System.out.println(grade);
			if (grade==null) {
				row.add(null);
			}else{
				row.add(grade.getGrade());
			}
		}
		cjb.add(row);
	}
	return cjb;

	*/
	return gradeDAO.getCjb(bjId, courses);
}
}
